<?php
namespace app\index\controller;

use think\Request;
use app\common\model\User;
use app\common\model\Account;
use app\common\model\Entrust;
use app\common\model\Contract;
use app\common\model\CapitalFlow;
use app\common\model\Deal;
use app\common\model\Depot;

class Monitor extends Common
{
    protected $User;
    private $Account;
    protected $Entrust;
    protected $Contract;
    protected $CapitalFlow;
    protected $Deal;
    protected $Depot;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->User = new User();
        $this->Account = new Account();
        $this->Enturst = new Entrust();
        $this->Constract = new Contract();
        $this->CapitalFlow = new CapitalFlow();
        $this->Deal = new Deal();
        $this->Depot = new Depot();
    }
    /*

    * 持仓记录

    */
    public function monitor(){
        $name = trim(input('get.name'));
        $ma = '';
        if ($name) {
            $ma['name|phone|real_name'] = $name;
        }
        $agent = $this->User->where($ma)->find();
        if ($agent) {
            $map['uid'] = $agent['id'];
        }else{
            $map['uid'] = $name;
        }
        $map = $this->query_time($map, input('get.start_query'), input('get.end_query'));
        $current_page = page_judge(input('get.page'));
        $list = $this->CapitalFlow->query_log($map, $current_page, $this->num,'');
        $page = page_handling($list['num'], $current_page, $this->show, $list['total']);
        // $bond = $this->Deal->where($map)->sum('bond');
        // $this->assign('bond', $bond);
        $this->assign('arr', $this->arr_info(input('get.')));
        $this->assign('empty', $this->null_html(12));
        $this->assign('page', $page);
        $this->assign('list', $list['data']);
        return $this->fetch();
    }
    /*

    * 持仓记录

    */
    public function depot(){
        $name = trim(input('get.name'));
        $ma = '';
        if ($name) {
            $ma['name|phone|real_name'] = $name;
        }
        $agent = $this->User->where($ma)->find();
        if ($agent) {
            $map['uid'] = $agent['id'];
        }else{
            $map['name'] = $name;
        }
        $map['status'] = 0;
        $map = $this->query_time($map, input('get.start_query'), input('get.end_query'));
        $current_page = page_judge(input('get.page'));
        $list = $this->Depot->query_log($map, $current_page, $this->num,'');
        $page = page_handling($list['num'], $current_page, $this->show, $list['total']);
        // $bond = $this->Deal->where($map)->sum('bond');
        // $this->assign('bond', $bond);
        $this->assign('arr', $this->arr_info(input('get.')));
        $this->assign('empty', $this->null_html(12));
        $this->assign('page', $page);
        $this->assign('list', $list['data']);
        return $this->fetch();
    }
/*

    * 持仓汇总

    */
    public function depotall(){
        $name = trim(input('get.name'));
        $ma = '';
        if ($name) {
            $ma['name|phone|real_name'] = $name;
        }
        $agent = $this->User->where($ma)->find();
        if ($agent) {
            $map['uid'] = $agent['id'];
        }else{
            $map['name'] = $name;
        }
        $map = $this->query_time($map, input('get.start_query'), input('get.end_query'));
        $current_page = page_judge(input('get.page'));
        $list = $this->Depot->query_log($map, $current_page, $this->num,'');
        $page = page_handling($list['num'], $current_page, $this->show, $list['total']);
        // $bond = $this->Deal->where($map)->sum('bond');
        // $this->assign('bond', $bond);
        $this->assign('arr', $this->arr_info(input('get.')));
        $this->assign('empty', $this->null_html(12));
        $this->assign('page', $page);
        $this->assign('list', $list['data']);
        return $this->fetch();
    }
}